﻿using HlELock.Core;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace HlELock
{
    public static class FunctionalExtensions
    {
        public static ObservableCollection<T> ToObservableCollection<T>(this IEnumerable<T> items)
        {
            ObservableCollection<T> observableCollection = new ObservableCollection<T>();
            foreach (T item in items)
            {
                observableCollection.Add(item);
            }

            return observableCollection;
        }

        public static string ToHexString(this byte[] bytes)
        {
            var result = bytes.Select(s => s.ToString("X2"));
            return string.Join("", result);
        }

        public static bool Required(this string str, string descr)
        {
            if (string.IsNullOrWhiteSpace(str))
            {
                var txt = AppHelper.GetResourceString("BiXuTianXie");
                MessageBox.Show(descr + txt);
                return false;
            }
            else
            {
                return true;
            }
        }
        public static bool Required(this int i, string descr)
        {
            if (i == default)
            {
                var txt = AppHelper.GetResourceString("BiXuTianXie");
                MessageBox.Show(descr + txt);
                return false;
            }
            else
            {
                return true;
            }
        }
    }
}
